home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Performance Co-Pilot 1.3
/
SGI Performance Co-Pilot 1.3.iso
/
dist
/
pcp.idb
/
usr
/
pcp
/
bin
/
pmnewlog.z
/
pmnewlog
Wrap
Text File
|
1997-04-03
|
9KB
|
436 lines
#!/bin/sh
#
# Copyright 1995, Silicon Graphics, Inc.
# ALL RIGHTS RESERVED
#
# UNPUBLISHED -- Rights reserved under the copyright laws of the United
# States. Use of a copyright notice is precautionary only and does not
# imply publication or disclosure.
#
# U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
# Use, duplication or disclosure by the Government is subject to restrictions
# as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
# in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
# in similar or successor clauses in the FAR, or the DOD or NASA FAR
# Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
# 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
#
# THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
# INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
# DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
# PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
# GRAPHICS, INC.
#
# stop and restart a pmlogger instance
#
# $Id: pmnewlog.sh,v 2.1 1997/03/26 03:05:37 kenmcd Exp $
tmp=/tmp/$$
status=0
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
prog=`basename $0`
_abandon()
{
echo
echo "Sorry, but this is fatal. No new pmlogger instance has been started."
status=1
exit
}
_check_pid()
{
ps -ef \
| nawk '
/<defunct>/ { next }
$2 == '$1' { print $2 }'
}
_check_logfile()
{
if [ ! -f $logfile ]
then
echo "Cannot find pmlogger output file at \"$logfile\""
else
echo "Contents of pmlogger output file \"$logfile\" ..."
cat $logfile
fi
}
_check_logger()
{
# wait until pmlogger process starts, or exits
#
delay=5
[ ! -z "$PMCD_CONNECT_TIMEOUT" ] && delay=$PMCD_CONNECT_TIMEOUT
x=5
[ ! -z "$PMCD_REQUEST_TIMEOUT" ] && x=$PMCD_REQUEST_TIMEOUT
# wait for maximum time of a connection and 20 requests
#
delay=`expr $delay + 20 \* $x`
i=0
while [ $i -lt $delay ]
do
echo ".\c"
if echo "connect $1" | pmlc >$tmp.out 2>&1
then
if grep "Unable to connect" $tmp.out >/dev/null
then
:
else
sleep 5
echo " done"
return 0
fi
fi
if ps -ef | grep pmlogger | nawk '
BEGIN { sts=0 }
$2 == '$1' { sts=1; exit sts }
END { exit sts }'
then
echo " process exited!"
_check_logfile
return 1
fi
sleep 5
i=`expr $i + 5`
done
echo " timed out waiting!"
sed -e 's/^/ /' $tmp.out
_check_logfile
return 1
}
primary=true
myname="primary pmlogger"
connect=primary
access=""
config=""
saveconfig=""
logfile="pmlogger.log"
namespace=""
args=""
sock_me=""
usage="Usage: $prog"' [-a accessfile] [-c configfile] [-C saveconfig]
[-l logfile] [-L] [-n namespace] [-p pid] [-s] [-v volsamples] archive'
# option parsing
#
while getopts a:c:C:l:Ln:p:sv: c
do
case $c
in
a) access="$OPTARG"
if [ ! -f $access ]
then
echo "$prog: Error: cannot find accessfile ($access)"
_abandon
fi
;;
c) config="$OPTARG"
if [ ! -f $config ]
then
if [ -f /var/pcp/config/pmlogger/$config ]
then
config="/var/pcp/config/pmlogger/$config"
else
echo "$prog: Error: cannot find configfile ($config)"
_abandon
fi
fi
;;
C) saveconfig="$OPTARG"
;;
l) logfile="$OPTARG"
;;
L) args="$args-L "
;;
n)
namespace="-n $OPTARG"
args="$args-$c $OPTARG "
;;
p) pid=$OPTARG
primary=false
myname="pmlogger (pid $pid)"
connect=$pid
;;
s)
sock_me="pmsocks "
;;
v)
args="$args-$c $OPTARG "
;;
\?) echo "$usage"
_abandon
;;
esac
done
shift `expr $OPTIND - 1`
if [ $# -ne 1 ]
then
echo "$usage"
_abandon
fi
# initial sanity checking for new archive name
#
archive=$1
if [ -f $archive.0 -o -f $archive.index -o -f $archive.meta ]
then
echo "$prog: Error: archive \"$archive\" exists, pmlogger would fail on restart"
ls -l $archive.*
_abandon
fi
# check that designated pmlogger is really running
#
echo "Looking for $myname ...\c"
ps -ef \
| if $primary
then
grep 'pmlogger .*-P' | grep -v grep
else
nawk '$2 == '"$pid"' && /pmlogger/ { print }'
fi >$tmp.out
if [ -s $tmp.out ]
then
echo " found"
cat $tmp.out
pid=`nawk '{ print $2 }' <$tmp.out`
else
echo " Error: process not found"
_abandon
fi
# pass primary/not primary down
#
$primary && args="$args-P "
# pass logfile option down
#
args="$args-l $logfile "
# if not a primary pmlogger, get name of pmcd host pmlogger is connected to
#
if $primary
then
:
else
# start critical section ... no interrupts due to pmlogger SIGPIPE
# bug in PCP 1.1
#
trap "echo; echo $prog:' Interrupt! ... I am talking to pmlogger, please wait ...'" 1 2 3 15
echo "Getting logged host name from $myname ...\c"
( echo "connect $connect" ; echo "status" ) \
| pmlc 2>$tmp.err >$tmp.out
# end critical section
#
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
if [ -s $tmp.err ]
then
if grep "Unable to connect" $tmp.err >/dev/null
then
echo " failed to connect"
echo
sed -e 's/^/ /' $tmp.err
_abandon
else
echo
echo "$prog: Warning: errors from talking to $myname via pmlc"
sed -e 's/^/ /' $tmp.err
echo
echo "continuing ..."
fi
else
echo " done"
fi
host=`sed -n -e '/^pmlogger/s/.* from host //p' <$tmp.out`
if [ "X$host" = X ]
then
echo "$prog: Error: failed to get host name from $myname"
echo "This is what was collected from $myname."
echo
sed -e 's/^/ /' $tmp.out
_abandon
fi
args="$args-h $host "
fi
# extract/contruct config file if required
#
if [ "X$config" = X ]
then
# start critical section ... no interrupts due to pmlogger SIGPIPE
# bug in PCP 1.1
#
trap "echo; echo $prog:' Interrupt! ... I am talking to pmlogger, please wait ...'" 1 2 3 15
echo "Contacting $myname to get logging state ...\c"
# iterate over top-level names in pmns, and query pmlc for
# current configuration ... note exclusion of "proc" metrics
# ... others may be excluded in a similar fashion
#
( echo "connect $connect" \
; for top in `pminfo $namespace \
| sed -e 's/\..*//' -e '/^proc$/d' \
| sort -u`
do
echo "query $top"
done \
) \
| pmlc $namespace 2>$tmp.err \
| nawk >$tmp.out '
/^[^ ]/ { metric = $1; next }
$1 == "mand" || ( $1 == "adv" && $2 == "on" ) { print $0 " " metric }'
# end critical section
#
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
if [ -s $tmp.err ]
then
if grep "Unable to connect" $tmp.err >/dev/null
then
echo " failed to connect"
echo
sed -e 's/^/ /' $tmp.err
_abandon
else
echo
echo "$prog: Warning: errors from talking to $myname via pmlc"
sed -e 's/^/ /' $tmp.err
echo
echo "continuing ..."
fi
else
echo " done"
fi
if [ ! -s $tmp.out ]
then
echo "$prog: Error: failed to collect configuration info from $myname"
echo "Most likely this pmlogger instance is inactive."
_abandon
fi
# convert to a pmlogger config file
#
sed <$tmp.out >$tmp.config \
-e 's/ on nl/ on/' \
-e 's/ off nl/ off/'\
-e 's/ *mand *\(o[nf]*\) /log mandatory \1 /' \
-e 's/ *adv *on /log advisory on/' \
-e 's/\[[0-9][0-9]* or /[/' \
-e 's/\(\[[^]]*]\) \([^ ]*\)/\2 \1/' \
-e 's/ */ /g'
if [ ! -s $tmp.config ]
then
echo "$prog: Error: failed to generate a pmlogger configuration file for pmlogger"
echo "This is what was collected from $myname."
echo
sed -e 's/^/ /' $tmp.out
_abandon
fi
config=$tmp.config
fi
# optionally append access control specifications
#
if [ "X$access" != X ]
then
if grep '\[access]' $config >/dev/null
then
echo "$prog: Error: pmlogger configuratiuon file already contains an"
echo " access control section, specifications from \"$access\" cannot"
echo " be applied."
_abandon
fi
cat $access >>$config
fi
# add config file to the args, save config file if -C
#
args="$args-c $config "
if [ "X$saveconfig" != X ]
then
if cp $config $saveconfig
then
echo "New pmlogger configuration file saved as $saveconfig"
else
echo "$prog: Warning: unable to save configuration file as $saveconfig"
fi
fi
# kill off existing pmlogger
#
echo "Terminating $myname ...\c"
for sig in INT HUP KILL
do
echo " SIG$sig ...\c"
kill -$sig $pid
sleep 1
[ "`_check_pid $pid`" = "" ] && break
done
# the archive folio Latest is for the most recent archive in this directory
#
dir=`dirname $archive`
rm -f $dir/Latest
if [ "`_check_pid $pid`" = "" ]
then
echo " done"
else
echo " failed!"
_abandon
fi
# clean up port-map, just in case
#
PM_LOG_PORT_DIR=/var/tmp/pmlogger
rm -f $PM_LOG_PORT_DIR/$pid
$primary && rm -f $PM_LOG_PORT_DIR/primary $PM_LOG_PORT_DIR/vcr
# finally do it, ...
#
cd $dir
[ "X$dir" = X. ] && dir=`pwd`
archive=`basename $archive`
echo "Launching new pmlogger in directory \"$dir\" as ..."
[ -f $logfile ] && mv -f $logfile $logfile.prior
echo "${sock_me}/usr/pcp/bin/pmlogger $args$archive"
${sock_me}/usr/pcp/bin/pmlogger $args$archive &
new_pid=$!
echo "Waiting for new pmlogger to start ..\c"
if _check_logger $new_pid
then
echo "New pmlogger status ..."
( echo "connect $new_pid"; echo "status" ) | pmlc
# make the "Latest" archive folio
#
[ -f $archive.0 ] && /usr/pcp/bin/mkaf $archive.0 >Latest
exit
else
_abandon
fi